#include "stdafx.h"
#include <string>
#include <list>

using namespace std;

namespace tinyXMLNodes{

	enum NodeType {ElementNode, TextNode, CDATANode, CommentNode};

	class Node;
	class Attribute;
																																																																																										class Node {
	class Node {
    string name;                    //Name of the node.
    int numberOfChildren;            //Number of children of this node.
    bool isRoot;                    /// Necessary?
    bool isLeaf;                    /// Necessary?
    NodeType nodeType;
    Node* parentNode;                //Pointer to the parent node.

    list<Node*> childNodes;            //List of child nodes.
    list<Attribute *> attributes;    //List of attributes associated with this node.

public:
    list<Node*> getChildren() {
        return childNodes;
    }

    Node getNextSibling() {
        //Code to return the next sibling of the node.
    }

    Node getPreviousSibling() {
        //Code to return the previous sibling of the node.
    }

    int addChildNode (Node* child) {
        childNodes.push_back(child);
        ++numberOfChildren;
        return 0;
    }

    int addChildNode (Node* child, int index) {
        if (index > numberOfChildren) {
            return -1;
        }
        list<Node*>::iterator it = childNodes.begin();
        int temp = 0;
        while (it != childNodes.end()) {
            if (temp == index) {
                childNodes.insert(it, child);
                ++numberOfChildren;
                return 0;
            }
            ++temp;
            ++it;
        }
        if (temp == index) {
            childNodes.insert(it, child);
            ++numberOfChildren;
            return 0;
        }
        return -1;
    }

    int addChildNode (string childName) {            //Do we need this? How are we gonna know the type of node to add?
    }
    int addChildNode (string childName, int index) {
    }

    int addAttribute (Attribute* attrib) {            //Function to add an attribute to the node.
        attributes.push_back(attrib);
        return 0;
    }

    int addTextChild (string content) {
    }

    int addCDATAChild (string content) {
    }

    int addCommentChild (string content) {
    }

    int removeChild (Node* child) {
        list<Node*>::iterator it = childNodes.begin();
        while (it != childNodes.end()) {
            if (*it == child) {
                childNodes.erase(it);
                --numberOfChildren;
                return 0;
            }
        }
        return -1;
    }

    int removeChild (int index) {
        if (index >= numberOfChildren) {
            return -1;
        }
        list<Node*>::iterator it = childNodes.begin();
        int temp = 0;
        while (it != childNodes.end()) {
            if (temp == index) {
                childNodes.erase(it);
                --numberOfChildren;
                return 0;
            }
            ++temp;
            ++it;
        }
        return -1;
    }
};

	class TextNode : public Node {
	};

	class CDATANode : public Node {
};

	class CommentNode : public Node {
	};

	class ElementNode : public Node {
	};

}